import { Validator } from "vee-validate";
// 手机号验证
Validator.extend("phone", {
  getMessage: (field: string) => `The ${field} field must be a valid Phone`,
  validate: (value: string) => {
    return (
      value.length == 11 && /^((13|14|15|17|18)[0-9]{1}\d{8})$/.test(value)
    );
  },
});
// 美元校验开头不能为0
Validator.extend("usd", {
  getMessage: (field: string) => `The ${field} field must be a valid Usd`,
  validate: (value: string) => {
    return /^(([1-9]\d{0,2}(,\d{3})*(\.\d{1,2})?)|0)$/.test(value);
  },
});
// 百分比校验不带百分比符号开头不能为0
Validator.extend("percentage", {
  getMessage: (field: string) =>
    `The ${field} field must be a valid Percentage`,
  validate: (value: string) => {
    return /^(([1-9]\d?(\.\d{1,2})?)|0)$/.test(value);
  },
});
// 手机号和座机号验证
Validator.extend("mobile", {
  getMessage: (field: string) => `The ${field} field must be a valid Phone`,
  validate: (value: string) => {
    return /^((\d{3,4}-)?[0-9]{7,8})|((13|14|15|17|18)[0-9]{1}\d{8})$/.test(
      value
    );
  },
});
